Walkthrough 9-1: Multicast an event
In this walkthrough, you create a flow that calls each of the three airline services and combines the results. You will:
· Use a Scatter-Gather router to concurrently call all three flight services.
· Use DataWeave to flatten multiple collections into one collection.
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow
1. Return to implementation.xml.
2. From the Mule Palette, drag an HTTP Listener and drop it at the top of the canvas.
3. Change the flow name to getAllAirlineFlights.
4. In the Listener properties view, set the display name to GET /flights.
5. Ensure the connector configuration is set to the existing HTTP_Listener_config.
6. Set the path to /flights and the allowed methods to GET.
Browse the flow control elements in the Mule Palette
7. In the Core section of the Mule Palette, locate the Flow Control elements.
Add a Scatter-Gather to call all three airline services
8. Drag a Scatter-Gather flow control element from the Mule Palette and drop it in the process section of getAllAirlineFlights.
9. Add three parallel Flow Reference components to the Scatter-Gather router.
10. In the first Flow Reference properties view, set the flow name and display name to getAmericanFlights.
11. Set the flow name and display name of the second Flow Reference to getUnitedFlights.
12. Set the flow name and display name of the third Flow Reference to getDeltaFlights.
13. Add a Logger after the Scatter-Gather.
Review the metadata for the Scatter-Gather output
14. In the Logger properties view, explore the input payload structure in the DataSense Explorer.
Debug the application
15. Add a breakpoint to the Scatter-Gather.
16. Add a breakpoint to the Logger.
17. Save the file to redeploy the project in debug mode.
18. In Advanced REST Client, change the URL to make a request to http://localhost:8081/flights.
19. In the Mule Debugger, step through the application; you should step through each of the airline flows.
20. Stop at the Logger after the Scatter-Gather and explore the payload.
21. Drill-down into one of the objects in the payload.
22. Step through the rest of the application and switch perspectives.
23. Return to Advanced REST Client and review the response; you should get a 500 Server Error with a message that the object could not be serialized.
Flatten the combined results
24. Return to Anypoint Studio.
25. In getAllAirlineFlights, add a Transform Message component before the Logger.
26. Change the display name to flatten to [Flight].
27. In the input section of the Transform Message properties view, review the payload data structure.
28. In the expression section, use the DataWeave flatten function to flatten the collection of objects into a single collection.
Debug the application
29. Save the file to redeploy the project.
30. In Advanced REST Client, make the same request to http://localhost:8081/flights.
31. In the Mule Debugger, press Resume until you are stopped at the Logger at the end of the Scatter-Gather; you should see the payload is now one ArrayList of Flights.
32. Step through the rest of the application and switch perspectives.